﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Zhaoxi.FactoryDeviceSystem.UControls
{
    public partial class UCircle : Label
    {
        Rectangle rect;//绘制区域
        public UCircle()
        {
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);//忽略窗口消息，减少闪烁
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);//绘制到缓冲区，减少闪烁
            SetStyle(ControlStyles.UserPaint, true);//控件由其自身而不是操作系统绘制
            SetStyle(ControlStyles.ResizeRedraw, true);//控件调整其大小时重绘
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);//支持透明背景
            this.BackColor = Color.Transparent;
            this.Size = new Size(30, 30);
            rect = this.ClientRectangle;
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            rect = this.ClientRectangle;
            this.Region = new Region(rect);
        }

        public override string Text { get => ""; }

        public override bool AutoSize { get => false; }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            //绘制圆形
            Graphics g = e.Graphics;//绘图对象           
            g.SmoothingMode = SmoothingMode.HighQuality;  //呈现质量--高质量呈现 
            Rectangle rect1=new Rectangle(rect.X+1,rect.Y+1,rect.Width-2,rect.Height-2);//椭圆所有的矩形
            g.FillEllipse(new SolidBrush(this.ForeColor), rect1);
        }
    }
}
